home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2002 #11 / Amiga Plus CD - 2002 - No. 11.iso / Tools / Development / Feelin021015 / Examples / Class2.c < prev    next >
C/C++ Source or Header  |  2002-10-28  |  6KB  |  199 lines

  1. #include <stdlib.h>
  2.  
  3. #include <clib/exec_protos.h>
  4. #include <clib/dos_protos.h>
  5. #include <clib/graphics_protos.h>
  6. #include <clib/feelin_protos.h>
  7.  
  8. #include <graphics/gfx.h>
  9. #include <graphics/rastport.h>
  10. #include <libraries/feelin.h>
  11.  
  12. struct FeelinBase *FeelinBase;
  13.  
  14. /// OBJ
  15. /* Here is the beginning of our simple new class... */
  16.  
  17. #define FM_Strobo FCCM_BASE
  18.  
  19. struct LocalObjectData {
  20.       struct FeelinSignalHandler    psSignalHandler;
  21. };
  22. //+
  23.  
  24. /// mNew
  25. ULONG SAVEDS mNew(struct FeelinClass *psClass,APTR Obj,struct LocalObjectData *psLOD,ULONG *pnArgs)
  26. {
  27.    psLOD -> psSignalHandler.Object   = Obj;
  28.    psLOD -> psSignalHandler.Method   = FM_Strobo;
  29.    psLOD -> psSignalHandler.Flags    = FF_SignalHandler_Timer;
  30.    psLOD -> psSignalHandler.Signals  = 0;      // Secs
  31.    psLOD -> psSignalHandler.Reserved = 30000;  // Micros
  32.  
  33.    return F_SuperDoA(psClass,Obj,FM_New,pnArgs);
  34. }
  35. //+
  36. /// mAskMinMax
  37. /*
  38. AskMinMax method will be called before the  window  is  opened  and  before
  39. layout  takes place. We need to tell Feelin the minimum and maximum size of
  40. our object. Note that we indeed need to *add* these values,  not  just  set
  41. them !
  42. */
  43.  
  44. ULONG SAVEDS mAskMinMax(struct FeelinClass *psClass,APTR Obj,ULONG *pnArgs)
  45. {
  46.  
  47.    _minw(Obj) += 30;
  48.    _minh(Obj) += 30;
  49.  
  50. /*
  51. Now call our superpsClassass. Area.fcc will handle everything,  taking  care  of
  52. FA_FixedXxx, FA_MinXxx and FA_MaxXxx.
  53. */
  54.  
  55.    return F_SuperDoA(psClass,Obj,FM_AskMinMax,pnArgs);
  56. }
  57. //+
  58. /// mDraw
  59. /*
  60. Draw method is called whenever  Feelin  feels  (obviously  ;-))  we  should
  61. render our object. This usually happens after layout is finished. Note: You
  62. may only render within the rectangle _mleft(paObj), _mtop(paObj), _mwidth(paObj),
  63. _mheight(paObj).
  64. */
  65. ULONG SAVEDS mDraw(struct FeelinClass *psClass,APTR Obj,struct FS_Draw *psDraw)
  66. {
  67.    struct RastPort *rp;
  68.  
  69.    rp = _rp(Obj);
  70.  
  71. /*
  72. let our superclass draw itself first, Area class would e.g. draw the  frame
  73. and clear the whole region. What it does exactly depends on flags.
  74. */
  75.  
  76.    F_SuperDoA(psClass,Obj,FM_Draw,(ULONG *)psDraw);
  77.  
  78.    _APen(rand());
  79.    _Boxf(_mx(Obj),_my(Obj),_mx2(Obj),_my2(Obj));
  80.  
  81.    return NULL;
  82. }
  83. //+
  84. /// mShow
  85. ULONG SAVEDS mShow(struct FeelinClass *psClass,APTR Obj,struct LocalObjectData *psLOD,ULONG *pnArgs)
  86. {
  87.    F_SuperDoA(psClass,Obj,FM_Show,pnArgs);
  88.    F_Do(_client(Obj),FM_Client_AddSignalHandler,&psLOD -> psSignalHandler);
  89.    return NULL;
  90. }
  91. //+
  92. /// mHide
  93. ULONG SAVEDS mHide(struct FeelinClass *psClass,APTR Obj,struct LocalObjectData *psLOD,ULONG *pnArgs)
  94. {
  95.    F_Do(_client(Obj),FM_Client_RemSignalHandler,&psLOD -> psSignalHandler);
  96.    return F_SuperDoA(psClass,Obj,FM_Hide,pnArgs);
  97. }
  98. //+
  99. ///myDispatcher
  100. /*
  101. Here comes the dispatcher for our custom psClassass. Unknown/unused methods  are
  102. passed to the superclass immediately.
  103. */
  104.  
  105. ULONG ASM SAVEDS myDispatcher(REG_A2 struct FeelinClass *psClass,REG_A0 APTR Obj,REG_D0 ULONG nMethod,REG_A1 ULONG *pnArgs)
  106. {
  107.    struct LocalObjectData *psLOD = INST_DATA(psClass,Obj);
  108.  
  109.    switch (nMethod)
  110.    {
  111.       case FM_New:         return mNew       (psClass,Obj,psLOD,pnArgs);
  112.  
  113.       case FM_Show:        return mShow      (psClass,Obj,psLOD,pnArgs);
  114.       case FM_Hide:        return mHide      (psClass,Obj,psLOD,pnArgs);
  115.       case FM_AskMinMax:   return mAskMinMax (psClass,Obj,pnArgs);
  116.       case FM_Draw:        return mDraw      (psClass,Obj,(struct FS_Draw *)pnArgs);
  117.  
  118.       case FM_Strobo:             F_Draw(Obj,FF_Draw_Update);
  119.                            return TRUE;
  120.  
  121.       default:             return F_SuperDoA(psClass,Obj,nMethod,pnArgs);
  122.    }
  123. }
  124. //+
  125.  
  126. ///Main
  127. void main()
  128. {
  129.    APTR c,w;
  130.    struct FeelinClass *cc;
  131.  
  132.    if (FeelinBase = (struct FeelinBase *)OpenLibrary("feelin.library",FV_VERSION))
  133.    {
  134.  
  135. /*
  136. Create the new custom class with a call to F_CreateClassA().
  137.  
  138. This function returns a struct FeelinClass. You must use cc -> ID to create
  139. instance   of   your   custom   class.  This  ID  is  unique  and  made  by
  140. F_CreateClassA().
  141. */
  142.  
  143.       if (cc = F_CreateClass(FA_SuperID,     FC_Area,
  144.                              FA_DataSize,    sizeof (struct LocalObjectData),
  145.                              FA_Dispatcher,  myDispatcher,
  146.                              TAG_DONE))
  147.       {
  148.          c = ClientObject,
  149.             FA_Client_Title,        "Class2",
  150.             FA_Client_Version,      "$VER: Class2 0.02 (22.10.01)",
  151.             FA_Client_Copyright,    "© 2001 by Laviale Olivier",
  152.             FA_Client_Author,       "Laviale Olivier (lotan9@aol.com)",
  153.             FA_Client_Description,  "Tutorial on Client.AddInputHandler()",
  154.             FA_Client_Base,         "CLASS2",
  155.  
  156.             Child, w = WindowObject,
  157.                FA_ID,           "MAIN",
  158.                FA_Window_Title, "Crazy colors using Client.AddSignalHandler()",
  159.                
  160.                Child, VGroup,
  161.                   Child, HGroup,
  162.                      Child, F_NewObj(cc -> ID,GaugeFrame, DontChain, TAG_DONE),
  163.                      Child, F_NewObj(cc -> ID,GaugeFrame, DontChain, TAG_DONE),
  164.                   End,
  165.  
  166.                   Child, HGroup,
  167.                      Child, F_NewObj(cc -> ID,GaugeFrame, DontChain, TAG_DONE),
  168.                      Child, F_NewObj(cc -> ID,GaugeFrame, DontChain, TAG_DONE),
  169.                   End,
  170.                End,
  171.             End,
  172.          End;
  173.  
  174.          if (c)
  175.          {
  176.             F_Do(w,FM_Notify,FA_Window_CloseRequest,TRUE, FV_Notify_Client,2,FM_Client_ReturnID,FV_Client_Quit);
  177.             F_Set(w,FA_Window_Open,TRUE);
  178.  
  179.             F_DoA(c,FM_Client_Run,NULL);
  180.  
  181.             F_DisposeObj(c);
  182.          }
  183.  
  184.          F_RemoveClass(cc);
  185.       }
  186.       else
  187.       {
  188.          Printf("Unable to create custom class.\n");
  189.       }
  190.  
  191.       CloseLibrary((struct Library *)FeelinBase);
  192.    }
  193.    else
  194.    {
  195.       Printf("Failed to open feelin.library.\n");
  196.    }
  197. }
  198. //+
  199.